package sever

import (
	"fmt"
	"travel-app/common/proto/user"
	"travel-app/pkg"
	"travel-app/rpc/model"
)

func Register(in *user.RegisterReq) (*user.RegisterResp, error) {
	u := model.User{}

	mobile, _ := u.GetUserMobile(in.Mobile)
	if mobile != nil {
		return nil, fmt.Errorf("注册失败,该用户已经注册")
	}

	_, err := u.CreateUser(in)
	if err != nil {
		return nil, fmt.Errorf("注册失败")
	}
	return &user.RegisterResp{Success: true}, err
}

func Login(in *user.LoginReq) (*user.LoginResp, error) {
	u := model.User{}

	mobile, _ := u.GetUserMobile(in.Mobile)
	if mobile == nil {
		return nil, fmt.Errorf("登录失败,该用户还未注册")
	}
	if mobile.Password != in.Password {
		return nil, fmt.Errorf("登录失败,密码输入错误")
	}
	return &user.LoginResp{Id: int64(mobile.ID)}, nil
}

func UserReal(in *user.UserRealReq) (*user.UserRealResp, error) {

	//u := model.UserReal{}
	//
	//createUser, err := u.CreateUser(in)
	//if err != nil {
	//	return nil, fmt.Errorf("实名认证失败")
	//}

	pkg.UserReal(in.Name, in.Card)

	fmt.Println(11111111111)
	fmt.Println(in.Name, in.Card)
	return &user.UserRealResp{Id: int64(1)}, nil
}
